#! /usr/bin/env python3
# -*- coding: utf-8 -*-
import logging
import signal
from wcferry import Wcf
from robot import Robot


def main_fun():
    wcf = Wcf(debug=True)

    def handler(sig, frame):
        wcf.cleanup()  # 退出前清理环境
        exit(0)
    get_all_id(wcf)
    # 退出程序
    signal.signal(signal.SIGINT, handler)
    # 初始化机器人
    robot = Robot(wcf)
    # 接收消息
    robot.enableReceivingMsg()  # 加队列
    # 每天10点发送问题，回答
    # robot.onEveryTime("10:00", robot.questionSend)
    # 开启定时调度
    robot.keepRunningAndBlockProcess()


def get_all_id(wcf):
    log = logging.getLogger("Robot")
    contacts = wcf.query_sql("MicroMsg.db", "SELECT UserName, NickName FROM Contact;")
    # UserName是指wxid或roomid、NickName是指群名或微信好友名
    all_info = {contact["UserName"]: contact["NickName"] for contact in contacts}
    log.info(all_info.__str__())


if __name__ == "__main__":
    main_fun()
